# -*- coding: utf-8 -*-
# @Time    : 2021/4/14 18:59
# @Author  : Chen
# @Email   : 2356458272@qq.com
# @File    : jihuoma.py
# @Software: PyCharm
import random
import string
d = {}
f = ""
with open("jhm.txt","a+",encoding="utf-8") as h:
    while 1:
        a = input("请输入你需要几个激活码：")
        if a.isdigit():
            for i in range(int(a)):
                for j in range(2):
                    b = random.choice(string.ascii_uppercase+string.digits)
                    if j == 0:
                        if f in d:
                            print(f"{f},重复")
                            h.write(f)
                            f = b
                        else:
                            d[f] = 1
                            if i == 0:
                                f = b
                                pass
                            else:
                                h.write("激活码"+str(i)+":")
                                h.write(f+"\n")
                                f = b
                        print("激活码",i+1,"：",b,end="")
                    else:
                        print(b,end="")
                        f += b
                else:
                    if i != int(a)-1:
                        print()
            else:
                h.write("激活码"+str(i+1)+":")
                h.write(f + "\n")
                break
        else:
            print("请输入数字")